package com.insurance.service.impl;

import com.insurance.common.Contants;
import com.insurance.common.ResultData;
import com.insurance.mapper.OrderMapper;
import com.insurance.service.OrderServcie;
import com.insurance.utils.ConversionDateUtils;
import net.bytebuddy.implementation.bytecode.Throw;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: 朱雄
 * Date: 2020/10/26 20:59
 * Description:
 * Version: V1.0
 */
@Service
public class OrderServiceImpl implements OrderServcie {

    @Autowired
    OrderMapper orderMapper;


    @Override
    public ResultData queryOrderType() throws SQLException{
        ResultData resultData=new ResultData();
        List<Map> list=orderMapper.queryOrderType();
        if (list.size()>0){
            resultData.setData(list);
            resultData.setCode(Contants.SUCCESS);
            resultData.setMsg("查询成功");
        }else {
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("查无数据");
        }
        return resultData;
    }

    @Override
    public ResultData queryOrderStatus() throws SQLException {
        ResultData resultData=new ResultData();
        List<Map> list=orderMapper.queryOrderStatus();
        if (list.size()>0){
            resultData.setData(list);
            resultData.setCode(Contants.SUCCESS);
            resultData.setMsg("查询成功");
        }else {
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("查无数据");
        }
        return resultData;
    }

    @Override
    public ResultData queryOrder() throws SQLException {
        ResultData resultData=new ResultData();
        /**
         * 查询订单信息
         */
        List<Map> list=orderMapper.queryOrder();
        /**
         * 查询图片附件地址
         */
        for (Map map1:list){
            if (map1.get("car_picktime")!=null){
                map1.put("car_picktime",ConversionDateUtils.conversionDateStringUtils(map1.get("car_picktime")));

            }
            if (map1.get("order_time")!=null){
                map1.put("order_time",ConversionDateUtils.conversionDateStringUtils(map1.get("order_time")));

            }
            if (map1.get("expectfinish_time")!=null){
                map1.put("expectfinish_time",ConversionDateUtils.conversionDateStringUtils(map1.get("expectfinish_time")));
            }
          String[] strings=  orderMapper.queryOrderImg(map1.get("order_number"));
          String[] strings2= orderMapper.queryOrderRegImg(map1.get("order_number"));;
            map1.put("repair_img_address",strings);
            map1.put("img_address",strings2);
        }
        if (list.size()>0){
            resultData.setData(list);
            resultData.setCode(Contants.SUCCESS);
            resultData.setMsg("查询成功");
        }else {
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("查无数据");
        }
        return resultData;
    }

    @Override
    public ResultData queryByMore(Map map) {

        if (map.get("order_time") !=null){
        map.put("order_time", ConversionDateUtils.conversionDateUtils(map.get("order_time").toString()));
        }
        if (map.get("order_time_end") !=null){
        map.put("order_time_end", ConversionDateUtils.conversionDateUtils(map.get("order_time_end").toString()));
        }
        ResultData resultData=new ResultData();
        /**
         * 查询订单信息
         */
        List<Map> list=orderMapper.queryByMore(map);
        /**
         * 查询图片附件地址
         */
        for (Map map1:list){
            if (map1.get("car_picktime")!=null){
                map1.put("car_picktime",ConversionDateUtils.conversionDateStringUtils(map1.get("car_picktime")));
            }
            if (map1.get("order_time")!=null){
                map1.put("order_time",ConversionDateUtils.conversionDateStringUtils(map1.get("order_time")));
            }
            if (map1.get("expectfinish_time")!=null){
                map1.put("expectfinish_time",ConversionDateUtils.conversionDateStringUtils(map1.get("expectfinish_time")));
            }
            String[] strings=  orderMapper.queryOrderImg(map1.get("order_number"));
            String[] strings2= orderMapper.queryOrderRegImg(map1.get("order_number"));;
            map1.put("repair_img_address",strings);
            map1.put("img_address",strings2);
        }
        resultData.setMsg("查询成功");
        if (list.size()>0){
        resultData.setData(list);
        resultData.setCode(Contants.SUCCESS);
        resultData.setMsg("查询成功");
        }else {
            resultData.setCode(Contants.FAILURE);
            resultData.setMsg("查无数据");
        }
        return resultData;
    }
}
